#
# this module look for libmetis support
# (http://www-users.cs.umn.edu/~karypis/metis/metis/index.html)
# it will define the following values
#
# LIBMETIS_INCLUDE_PATH = where metis.h can be found
# LIBMETIS_LIBRARY      = the library to link against libmetis
#

FIND_LIBRARY(LIBMETIS_LIBRARY metis
             /usr/lib 
             /usr/local/lib
             /sw/lib
             lib
)
FIND_PATH(LIBMETIS_INCLUDE_DIR metis.h 
          /usr/include
          /usr/local/include
          /sw/include
          include
)

IF(NOT LIBMETIS_LIBRARY)
  MESSAGE(STATUS "libmetis is not found in pre-defined paths.")
  MESSAGE(STATUS "We are using the version packaged with OHMMS instead.")
  MESSAGE(STATUS "NOTE!!! Don't worry.  We are not installing anything")
  MESSAGE(STATUS "to anywhere except to the OHMMS project directory.")
  IF(UNIX)
    IF(RUN_CONFIGURE)
      EXEC_PROGRAM(
       "${AUXPACKAGES}/metis/Lib/configure --prefix=${PROJECT_BINARY_DIR} --with-cc=${CMAKE _CC_COMPILER}"
        ${AUXPACKAGES}/metis/Lib
      )
      EXEC_PROGRAM(make ${AUXPACKAGES}/metis/Lib)
      EXEC_PROGRAM(make ${AUXPACKAGES}/metis/Lib ARGS install)
      FIND_LIBRARY(LIBMETIS_LIBRARY metis ${PROJECT_BINARY_DIR}/lib)
      # FIND_PATH(LIBMETIS_INCLUDE_DIR metis.h ${PROJECT_BINARY_DIR}/include)
      FIND_PATH(LIBMETIS_INCLUDE_DIR metis.h ${AUXPACKAGES}/metis/Lib)
    ENDIF(RUN_CONFIGURE)
  ENDIF(UNIX)
ENDIF(NOT LIBMETIS_LIBRARY)

IF(LIBMETIS_LIBRARY)
  MARK_AS_ADVANCED(LIBMETIS_INCLUDE_DIR LIBMETIS_LIBRARY)
  SET(HAVE_LIBMETIS 1)
  INCLUDE_DIRECTORIES(${LIBMETIS_INCLUDE_DIR})
  LINK_LIBRARIES(${LIBMETIS_LIBRARY})
ENDIF(LIBMETIS_LIBRARY)
